package com.c.ctgproject.ui.collect

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityPartInWerehouseDetailBinding
import com.c.ctgproject.entity.guang.PartInWarehouseEntity
import com.c.ctgproject.entity.guang.PartsInWarehouseEntity
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout
import com.c.ctgproject.wiget.dialog.ShowImgVideoFragment
import org.json.JSONObject

/**
 *作者:LiBW
 *创建日期: 2021/9/14
 *描述: 散件入库 详情
 */
class PartInWerehouseDetailActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityPartInWerehouseDetailBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root
    private val orderId by lazy { intent.getIntExtra(MyConstants.ORDER_ID, -1).handlerNull() }
    private val title by lazy { intent.getStringExtra(MyConstants.TITLE_NAME)?:"" }
    override fun event() {
        if(title.isNotEmpty()){
            mBinding.mTitleTV.setTitle(title)
        }

       if(orderId!="-1"){
           ApiMethods.apiSubscribe(ApiMethods.retrofit.blukPartDetail(orderId), MyObserverHandlerLoading(this, loading) {
               MyLog.d("散件入库详情回调:$it")
               val data = getGson().fromJson(it, PartsInWarehouseEntity::class.java).data
               data?.let {
                   mBinding.mContainer1.addView(CarInfoLayout(this, "订单编号", data.orderNo.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "创建人", data.createPersonName.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "创建时间", data.createTime.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "配件名称", data.partsName.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "配件来源", data.partsSource.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "配件数量", data.partsCount.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "数量单位", data.unit.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "过磅单号", data.poundNo.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "过磅重量KG", data.poundWeight.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "采购过磅单号", data.purchasePoundNo.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "采购重量KG", data.purchaseWeight.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "司机", data.driverName.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "司机车辆车牌", data.driverPlate.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "路桥费", data.toll.noDataHandler()))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "备注", data.remark.noDataHandler(),false))
                   mBinding.mContainer1.addView(CarInfoLayout(this, "磅单备注", data.poundRemark.noDataHandler(),false))
                   val image = data.poundPicture.handlerNull()
                   if (image.isNotEmpty()) {
                       mBinding.mImageView.visibility = View.VISIBLE
                       mBinding.mImageViewTV.visibility = View.VISIBLE
                       Glide.with(this).load(image).error(R.mipmap.app_icon).into(mBinding.mImageView)
                       mBinding.mImageView.setOnClickListener {
                           ShowImgVideoFragment(image).show(supportFragmentManager, "")
                       }
                   }
               }
           })
       }


//        val dataStr = intent.getStringExtra(MyConstants.DATA).handlerNull()
//        if (dataStr.isNotEmpty()) {
//            val data = getGson().fromJson(dataStr, PartInWarehouseEntity.DataBean.ListBean::class.java)

//
//
//        }
    }

    override fun click() {

    }
}